<template>
    <div>
        <table class="table table-bordered">
            <tbody>
                    <tr>
                <td>房型名称</td>
                <td><input type="text" v-model="info.houseTypeName"></td>
            </tr>
             <tr>
                <td>价格</td>
                <td><input type="text" v-model="info.price"></td>
            </tr>
            <tr>
                <td>图片</td>
                <td><input type="text" v-model="info.photo"></td>
            </tr>
            <tr>
                <td>是否有窗</td>
                <td><input type="radio" v-model="info.isWin" value="有" name="aa">有
                <input type="radio" v-model="info.isWin" value="无" name="aa">无
                </td>
            </tr>
              <tr>
                <td>状态</td>
                <td><input type="radio" v-model="info.state" value="启用" name="ab">启用
                <input type="radio" v-model="info.state" value="禁用" name="ab">禁用
                </td>
            </tr>
              <tr>
                <td>面积</td>
                <td><input type="text" v-model="info.area"></td>
            </tr>
              <tr>
                <td>入住人数</td>
                <td><input type="text" v-model="info.people"></td>
            </tr>
            <tr>
                <td>房型主题</td>
                <td>  <select v-model="info.themeId">
            <option value="">请选择</option>
            <option :value="item.id" v-for="item in level" :key="item.id">{{item.hotelName}}</option>  
        </select></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="button" value="添加" @click="add"></td>
            </tr>
            </tbody>
            
        </table>
        {{info}}
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';

let level:any=ref([]);
onMounted(()=>{
    GetLevel();
})
const GetLevel=()=>{
    axios({
        url:'https://localhost:7058/api/Hotel/GetLevel',
        method:'get',
    })
    .then((res)=>{
        console.log(res);
        level.value=res.data
    })
    .catch((err)=>{
        console.log(err);
    })
}
let info:any=ref({
  "houseTypeName": "",
  "price": "",
  "photo": "",
  "isWin": "",
  "isDel": true,
  "state": "",
  "area": "",
  "people": "",
  "themeId": ""
})
const add=()=>{
    if(info.value.houseTypeName=="")
    {
        alert("房型名称不能为空");
        return;
    }
    axios({
        url:"https://localhost:7058/api/Hotel/add",
        method:'post',
        params:info.value
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0){
            alert("添加成功");
        }
        else
        {
            alert("添加失败");
            return;
        }
    })
    .catch((err)=>{
        console.log(err);
    })
}
</script>

<style scoped>

</style>